#include "cmd.h"
#include "var.h"

int do_setenv(int argc, char **argv)
{
	char *pname, *pvalue;
	if (argc != 3)
		return -1;

	pname = argv[1], pvalue = argv[2];
	update_var(pname, pvalue);
	return 0;
}

void man_setenv(void)
{
	printf("Usage:\n\tsetenv [env] [value]\n");
}

int do_saveenv(int argc, char **argv)
{
	return save_var();
}

void man_saveenv(void)
{
	printf("Usage:\n\tsaveenv\n");
}

int do_unsetenv(int argc, char **argv)
{
	char *pname;
	if (argc != 2)
		return -1;
	pname = argv[1];

	return del_var(pname);
}

void man_unsetenv(void)
{
	printf("Usage:\n\tunsetenv [env]\n");
}

int do_printenv(int argc, char **argv)
{
	if (argc == 1)
		dump_var();
	else if (argc == 2) {
		char* pname = argv[1];
		Var* p_var = find_var(pname);
		if (p_var)
			show_var(p_var);
		else
			return -1;
	}
	return 0;
}

void man_printenv(void)
{
	printf("Usage:\n\tprintenv\n");
}

